﻿@{
    ViewData["Title"] = "FieldAdd";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
<h1 style="text-align:center">栏位新增</h1>
<form class="layui-form " action="" lay-filter="demo-val-filter" style="margin-top: 30px;">
    <div class="layui-form-item layui-col-md8">
        <label class="layui-form-label" style="font-size: 12px;">新增方式：</label>
        <div class="layui-input-block">
            <div class="layui-form">
                <input type="radio" value="1" title="单个新增" checked>
                <input type="radio" value="2" title="批量新增" >
            </div>
        </div>
    </div>
    <div class="layui-form-item layui-col-md8">
        <label class="layui-form-label" style="font-size: 12px;">栋舍名称：</label>
        <div class="layui-input-block">
            <input type="text" name="cottageName" id="cottageName" lay-verify="required" autocomplete="off" disabled style="width:400px" placeholder="请输入栏位名称" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item layui-col-md8">
        <label class="layui-form-label" style="font-size: 12px;">栏位名称：</label>
        <div class="layui-input-block">
            <input type="text" name="fieName" lay-verify="required" autocomplete="off" style="width:400px" placeholder="请输入栏位名称" class="layui-input">
        </div>
    </div>
    <input type="hidden" id="cottageId" name="cottageId" />

    <div class="layui-form-item">
        <div class="layui-input-block">
            <button type="submit" class="layui-btn" lay-submit lay-filter="demo1" >栏位新增</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</form>
@* <h1 style="text-align:center">栏位列表</h1> *@

@* <div style="margin:20px 20px">
    <body>
        <table id="ID-table-demo-setRowChecked"></table>
        <div id="pagesbox"></div>

        <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.0/jquery.min.js"></script>

        <div id="add-main" style="display: none;">
            <script>
                layui.use(['table', 'laypage', 'layer', 'form', 'layer', 'laydate'], function () {
                    var table = layui.table;
                    var laypage = layui.laypage;
                    var obj = {};
                    var form = layui.form;
                    var layer = layui.layer; // 添加layui弹出层模块
                    var laydate = layui.laydate;
                    // 渲染
                    laydate.render({
                        elem: '#sheeAccounts'
                    });

                    var size = 15; // 每页显示条数
                    //获取列表
                    function getListData(page) {
                        $.ajax({
                            url: 'http://10.31.60.18:8000/AuthorizationGetRout/api/Shee_Yand/FindShowCommonsShow',
                            type: 'get',
                            dataType: 'json',
                            data: {
                                page: page,
                                size: size,
                            },
                            success: function (res) {
                                table.render({
                                    elem: '#ID-table-demo-setRowChecked',
                                    cols: [[
                                        { type: 'checkbox', width: 60, fixed: 'center', unresize: true, align: 'center' },
                                        { field: 'number', type: 'numbers', title: '序号', width: 60, fixed: 'center', unresize: true, align: 'center', templet: '#zizeng' },
                                        { field: 'cottageId', title: '栋舍编号', width: 150, align: 'center' },
                                        { field: 'fieName', title: '栏位名称', width: 150, align: 'center' },
                                    ]],
                                    toolbar: '#demo-toolbar-setRowChecked',
                                    initSort: { // 设置初始排序
                                        field: 'experience', // 字段名
                                        type: 'asc' // 倒序
                                    },
                                    width:550,
                                    height:300,
                                    data: res.data
                                });
                                //分页
                                laypage.render({
                                    //挂载的分页id
                                    elem: 'pagesbox',
                                    count: res.tatalCount,
                                    limit: size,
                                    curr: page,
                                    layout: ['count', 'prev', 'page', 'next', 'skip'],
                                    jump: function (obj, first) {
                                        if (!first) {
                                            getListData(obj.curr);
                                        }
                                    }
                                });
                            }
                        });
                    }
                    $('#searchBtn').on('click', function () {
                        getListData(1);
                    });
                    // 初始化加载数据
                    $(function () {
                        getListData(1);
                    })
                });
            </script>
            <script type="text/html" id="barDemo">
                <div class="layui-btn-container">

                </div>
            </script>

    </body>
</div>
 *@
<script>

    var Id = location.search.substring(2).split("=")[1];
    console.log(Id);

    layui.use(['form', 'laydate'],
        function () {
            var id = window.location.search.split("=")[1];
            var $ = layui.$;
            var form = layui.form;
            var laydate = layui.laydate;
            laydate.render({
                elem: '#date'
            });
            function RestEmployee() {
                $(".layui-form").reset();
                form.render();
            };

            $(function () {
                FielCostesInfo();
            })

            function FielCostesInfo() {
                $.get("http://10.31.60.18:8000/AuthorizationGetRout/api/Cottage/FindIDCottage?cottageId=" + Id, function (res) {
                    console.log(res);
                    $("#cottageId").val(res.cottageId);
                    $("#cottageName").val(res.cottageName);
                   
                })
            }
            var obj = {};
            // 提交事件
            form.on('submit(demo1)', function (data) {
                var field = data.field;
                obj.cottageId = Id;
                obj.fieName = field.fieName;
                console.log(field);

                $.post({
                    url: "http://10.31.60.18:8000/AuthorizationSetRout/api/Field/CreateField",
                    data: JSON.stringify(field),
                    contentType: "application/json",
                    success: res => {
                        if (res > 0) {
                            var icon = 0;
                            layer.alert('添加成功', {
                                icon: 1,
                                shadeClose: true,
                                title: "栏位新增",
                            }, function () {
                                location.href = "/Cottage/CottageList";
                            });
                        } else {
                            layer.msg('添加失败：');
                        }
                    },
                    error: function () {
                        // 请求失败的处理
                        layer.msg('请求失败，请重试');
                    }
                });
                // 阻止表单默认提交
                return false;
            });
        })


</script>
